package pl.edu.agh.ki.neuralnetwork.layer;

import pl.edu.agh.ki.neuralnetwork.exceptions.NeuronNotConnectedException;
import pl.edu.agh.ki.neuralnetwork.neurons.InnerNeuron;
import pl.edu.agh.ki.neuralnetwork.neurons.SigmoidalNeuron;

public class BPInnerLayer extends BPAbstractLayer {

	public void computeErrors(Layer<InnerNeuron> upperLayer) {
		try {
			for (int i = 0; i < getNeuronsList().size(); i++) {
				SigmoidalNeuron sn = (SigmoidalNeuron)get(i);
				Double error = 0.0;
				for (int j = 0; j < upperLayer.getNeuronsList().size(); j++) {
					SigmoidalNeuron usn = (SigmoidalNeuron) upperLayer.get(j);
					error += usn.getError() * usn.getWeight(sn);
				}
				sn.setError(error);
			}
		} catch (NeuronNotConnectedException e) {
			e.printStackTrace();
		}
	}
	
}
